package com.pigs.pigsordersystem.controller;


import com.pigs.pigsordersystem.entity.AdminEntity;
import com.pigs.pigsordersystem.entity.ResultFormat;
import com.pigs.pigsordersystem.service.IAdminService;
import com.pigs.pigsordersystem.util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * <p>
 * 管理员 前端控制器
 * </p>
 *
 * @author Y.yang
 * @since 2020-03-14
 */
@RestController
@Api(value = "/admin",description = "管理员控制器")
@RequestMapping("/admin")
public class AdminController {

    private Logger logger = LoggerFactory.getLogger(AdminController.class);

    @Autowired
    private IAdminService adminService;
    @ApiOperation(value = "管理员登录")
    @PostMapping("login")
    public ResultFormat loginAdmin(String adminAccount, String adminPassword, HttpSession session) {

        AdminEntity adminEntity = adminService.loginAdmin(adminAccount, adminPassword);
        logger.info("adminEntity ={}",adminEntity );
        if (adminEntity!=null){
            session.setAttribute("adminAccount",adminAccount);
            return ResultUtil.success();
        }

        return ResultUtil.error(100,"密码或账号输出错误");
    }

}
